float4x4 World;
float4x4 View;
float4x4 Projection;

// TODO: add effect parameters here.

struct VertexShaderInput
{
    float4 Position : POSITION0;
	float3 Normal : NORMAL;
	float4 texCoord : TEXCOORD0;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float4 texCoord : TEXCOORD0;

    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

texture Texture;
sampler texSampler = sampler_state
{
	texture = <Texture>;
};

float2 size;
bool AlphaTest = true;
float AlphaTestValue = 0.5f;
bool AlphaTestGreater = true;

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
	float3 position = mul(input.Position, World);
	
	float3 viewDirection = -View._m02_m12_m22;

    float3 rightVector = normalize(cross(viewDirection, input.Normal));

    position += rightVector * (input.texCoord.x - 0.5) * size.x;
	position += input.Normal * (1 - input.texCoord.y) * size.y;
	output.Position = mul(float4(position, 1), mul(View, Projection));
	output.texCoord = input.texCoord;
	return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 color = tex2D(texSampler, input.texCoord);

	if(AlphaTest)
	{
		clip((color.a - AlphaTestValue) * (AlphaTestGreater ? 1 : -1));
	}
    return color;
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}
